FC = mpif90 

-include select_compiler.inc
#COMPILER = GNU/INTEL/PGI/IBM
#OPENMP = YES/NO
#GPU = YES/NO
#DEBUGGING = YES/NO
#FFTW = YES/NO

ifeq ($(COMPILER),GNU)
  DEBUG = -fbounds-check -ffpe-trap=zero,overflow,invalid,underflow -g
  OPT = -O3
endif
ifeq ($(COMPILER),INTEL)
  DEBUG = -fpe0 -traceback -C -g
  OPT = -O3 -ipo -xHost
endif
ifeq ($(COMPILER),PGI)
  DEBUG = -Ktrap=fp -traceback -g
  OPT = -fast -Minfo -Dpgf95 # needed for I/O LIB_VTK_IO
endif
ifeq ($(COMPILER),IBM)
  DEBUG = -C -qdbg=level=9 -qflttrap=invalid,nanq,overflow,zerodivide
  FC = mpixlf90 
  OPT = -O5 -qstrict
  DFLAGS = -WF,-DIBM
endif

ifeq ($(DEBUGGING),YES)
  FFLAGS = $(OPT) $(DEBUG)
else
  FFLAGS = $(OPT)
endif

MAIN = post_cubeflu

ifeq ($(FFTW),YES)
  LIBS =  -L$(FFTW_LIB) -lfftw3f -I$(FFTW_INC)
  FFTPOST = post-fft.o
  INCLUDES = -I$(FFTW_INC)
else
  FFTPOST = post-fft-dummy.o
endif

OBJ = IR_Precision.o Lib_VTK_IO.o basic_var_acc.o storage_allocatable.o mpi_utils_new.o mpi_decompose.o allocate_storage.o mod_tools.o $(MAIN).o print_screen_MPI.o post-init-eval.o reconstr_MPI.o inpout_MPI.o post_init.o $(FFTPOST)

%.o: %.f90 storage_allocatable.F90
	$(FC) $(FFLAGS) $(DFLAGS) -c $< $(INCLUDES)

%.o: %.F90 storage_allocatable.F90
	$(FC) $(FFLAGS) $(DFLAGS) -c $< $(INCLUDES)

main: $(OBJ) storage_allocatable.F90
	$(FC) $(FFLAGS) $(DFLAGS) $(OBJ) -o $(MAIN) $(LIBS)

all:
	make clean ; make

clean:
	rm -f $(OBJ) *.mod $(MAIN)
